<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:t="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="_csrf" th:content="${_csrf.token}">
    <meta name="_csrf_header" th:content="${_csrf.headerName}">
    <title th:text="${title}"></title>
    <script th:src="@{/js/easyui/base_loading.js}"></script>
    <link rel="stylesheet" th:href="@{/webjars/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/webjars/easyui/1.7.0/themes/material/easyui.css}">
    <link rel="stylesheet" th:href="@{/webjars/easyui/1.7.0/themes/icon.css}"/>
    <link rel="stylesheet" th:href="@{/webjars/easyui/1.7.0/themes/color.css}"/>
</head>
<body>
<!--<h2>CheckBox Tree</h2>
<p>Tree nodes with check boxes.</p>-->
<div style="margin:20px 0;">
    <!--<a href="#" class="easyui-linkbutton" onclick="getChecked()">GetChecked</a>-->
    <a href="javascript:void(0)" class="easyui-linkbutton  c-primary" style="width:80px" onclick="save()">保存</a>
</div>
<!--<div style="margin:10px 0">
    <input type="checkbox" checked onchange="$('#tt').tree({cascadeCheck:$(this).is(':checked')})">CascadeCheck
    <input type="checkbox" onchange="$('#tt').tree({onlyLeafCheck:$(this).is(':checked')})">OnlyLeafCheck
</div>-->
<div class="easyui-panel" style="padding:5px">
    <ul id="ttff"></ul>
</div>

<script th:src="@{/webjars/easyui/1.7.0/jquery.min.js}"></script>
<script th:src="@{/webjars/easyui/1.7.0/jquery.easyui.min.js}"></script>
<script th:src="@{/js/easyui/common.js}"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    $('#ttff').tree({
        url:'/api/roleAuthorities/authData?typeCode=' + [[${typeCode}]],
        method: 'get',
        animate:true,
        checkbox:true
    });
    function getChecked(){

        let nodes = $('#ttff').tree('getChecked');
        let s = '';
        for(let i=0; i<nodes.length; i++){
            if (s != '') s += ',';
            s += nodes[i].text;
        }
        alert(s);
    }

    function save() {
        let nodes = $('#ttff').tree('getChecked');
        let s = '';
        for(let i=0; i<nodes.length; i++){
            if (s != '') s += ',';
            s += nodes[i].id;
            if(nodes[i].linkId && nodes[i].linkId != 'null'){
                s += ',' + nodes[i].linkId;
            }
        }
        console.log(s);
        commonRequest({
           url:'/api/roleAuthorities/updateAuth',
           type:'POST',
           extraData: {
               ids: s,
               authority: [[${typeCode}]]
           }
        });
    }
    /*]]>*/
</script>
</body>
</html>